package com.cnd.scm.rabbitmq.config;


import com.cnd.scm.rabbitmq.producer.FastBuildRabbitMqProducer;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0
 * @ClassName: DetailResponse
 * @Description:
 * @author: 李启联
 * @date: 2021-02-24 10:57
 * @Copyright: Copyright (c), 2021
 */

@Configuration
@EnableRabbit
@ConditionalOnClass(FastBuildRabbitMqProducer.class)
public class RabbitMQAutoConfigure {

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
        return new RabbitTemplate(connectionFactory);
    }

    @Bean
    public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
        return new RabbitAdmin(connectionFactory);
    }

//    @Bean
//    @ConditionalOnMissingBean
//    public ConnectionFactory connectionFactory() {
//        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
//        return connectionFactory;
//    }

    @Bean
    @ConditionalOnMissingBean
    public FastBuildRabbitMqProducer fastRabbitMQProducer(ConnectionFactory connectionFactory){
        return new FastBuildRabbitMqProducer(connectionFactory);
    }
}
